#include <gtest/gtest.h>
#include <cstring>

#include "../physical_layer/serializers/InvertedListRecordSerializer.h"
#include "../physical_layer/file_system/InvertedListRecord.h"

using physical::byte;
using physical::InvertedListRecord;
using physical::InvertedListRecordSerializer;
using physical::InvertedList;

class InvertedListRecordSerializerTestFixture: public ::testing::Test
{
public:
	InvertedListRecordSerializerTestFixture() :
            m_serializer()
    {
        // initialization code here
    }

    void SetUp()
    {
        // code here will execute just before the test ensues
    }

    void TearDown()
    {
        // code here will be called just after the test completes
        // ok to through exceptions from here if need be
    }

    ~InvertedListRecordSerializerTestFixture()
    {
        // cleanup any pending stuff, but no exceptions allowed
    }

    // put in any custom data members that you need
    InvertedListRecordSerializer m_serializer;
};

TEST_F ( InvertedListRecordSerializerTestFixture, serializeDeserializeSequencialList )
{
    InvertedList invertedList = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    InvertedListRecord invertedListRecord (5, invertedList);
    InvertedListRecord deserializedInvertedList;

    size_t expectedSerializationBytes;
    size_t deserializedBytes;
    byte buffer[128];


    expectedSerializationBytes = m_serializer.getSize( invertedListRecord );

    m_serializer.serialize( invertedListRecord, buffer );

    deserializedBytes = m_serializer.deserialize( buffer,
            deserializedInvertedList );

    ASSERT_EQ( deserializedBytes, expectedSerializationBytes );
    ASSERT_EQ( deserializedInvertedList, invertedListRecord );
}
